package com.SpringBoot.orderDetail.service;

import com.SpringBoot.Util.Result;
import com.SpringBoot.orderDetail.mapper.OrderDetailMapper;
import com.SpringBoot.orderDetail.pojo.OrderDetail;
import org.springframework.stereotype.Service;

@Service
public class OrderDetailService {

    private final OrderDetailMapper orderDetailMapper;

    public OrderDetailService(OrderDetailMapper orderDetailMapper) {
        this.orderDetailMapper = orderDetailMapper;
    }

    public Result addOrderDetail(OrderDetail orderDetail) {
        orderDetailMapper.addOrderDetail(orderDetail);
        return Result.success(orderDetail.getDetailId());
    }

    public Result deleteOrderDetail(Integer detailId) {
        int rows = orderDetailMapper.deleteOrderDetail(detailId);
        if (rows > 0) {
            return Result.success("删除成功");
        }
        return Result.error(404, "订单明细不存在或已删除");
    }
    public Result getOrderDetailCount() {
        return Result.success(orderDetailMapper.getOrderDetailCount());
    }

    public Result completionRate(){
        return Result.success(orderDetailMapper.completionRate());
    }
}
